﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mediatheque.Areas.Admin.Models;

namespace mediatheque.Controllers
{
    public class CdController : Controller
    {
        private mediathequeEntities db = new mediathequeEntities();

        //
        // GET: /Cd/

        public ActionResult Index()
        {
            var list = from g in db.oeuvres
                       where g.type == "cd"
                       select g;

            if (list == null)
                return View("NotFound");
            else
                return View(list.ToList());
        }

        //
        // GET: /cd/Details/5

        public ActionResult Details(int id)
        {
            var cd = new AlbumsModel();
            //liste des albums (parent_id = 0)
            var chapitres = cd.getChapitresByOeuvreId(id);

            if (chapitres == null)
                return View("NotFound");
            else
            {
                //liste des titres par album
                List<int> parentIds = new List<int>();
                foreach (var item in chapitres)
                {
                    parentIds.Add(item.parent_id);
                }
                ViewData["albums"] = cd.getByList(parentIds);
                ViewData["id"] = id;
                return View(chapitres);
            }
        }

    }
}
